package com.nyist.threadCase;

import com.nyist.thread.NyistThreadUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * 1.
 *
 * @ClassName MyThreadRunnable
 * @Description
 * @Author xiaoyang
 * @Date 2023/04/03/20:19
 */
@Slf4j
public class MyThreadRunnableSum implements Runnable {

    static volatile int ticket = 100;
    static int sum = 0;

    public static void main(String[] args) throws InterruptedException {
        MyThreadRunnableSum myThreadRunnableSum = new MyThreadRunnableSum();
        Thread t1 = new Thread(myThreadRunnableSum);
        Thread t2 = new Thread(myThreadRunnableSum);

        t1.setName("runnable 111");
        t2.setName("runnable 222");

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println(sum);
    }

    @Override
    public void run() {
        for (int i = 0; i < ticket; i++) {
            sum++;
            NyistThreadUtils.sleep(10);
            log.info("=====>>>ThreadName:{} sum={}", NyistThreadUtils.getThreadName(), sum);
        }
    }

}